package Crist;

import java.util.*;

import dominio.Nodes;

/**
 *
 *
 * @author      Javier Garate
 */

public class Node extends Nodes{
    boolean isRoot;
    ArrayList<Node> children;

    public Node(int _n) {
				id = _n;
				children = null;
				isRoot = false;
    }

    public Node(int _n, boolean _isRoot) {
    			id = _n;
				children = null;
				this.isRoot = _isRoot;
    }

		public void addChild(Node _node) {
				if(children == null) children = new ArrayList<Node>();
				children.add(_node);
    }

   
    public void visitBuildRoute(ArrayList<Integer> _route) {
				_route.add(new Integer(id));
				if(children == null) return;
				for(int i = 0; i < children.size(); i++) {
						((Node)children.get(i)).visitBuildRoute(_route);
				}
    }

   
    public void visitFindOddDegreeNodes(ArrayList<Integer> _oddNodes) {
				if(children == null ) {
						_oddNodes.add(new Integer(id));
						return;
				}
				if (isRoot && children.size() % 2 != 0) _oddNodes.add(new Integer(id));
				if (!isRoot && children.size() % 2 == 0) _oddNodes.add(new Integer(id));
				for(int i = 0; i < children.size(); i++) {
						((Node)children.get(i)).visitFindOddDegreeNodes(_oddNodes);
				}
    }

    public int getNumber() {return id;}
}
